<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>添加信息</title>
	<meta name="renderer" content="webkit">	
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">	
	<meta name="apple-mobile-web-app-status-bar-style" content="black">	
	<meta name="apple-mobile-web-app-capable" content="yes">	
	<meta name="format-detection" content="telephone=no">	
	<link rel="stylesheet" type="text/css" th:href="@{/static/common/layui/css/layui.css}" media="all">
	<link rel="stylesheet" type="text/css" th:href="@{/static/common/bootstrap/css/bootstrap.css}" media="all">
	<link rel="stylesheet" type="text/css" th:href="@{/static/common/global.css}" media="all">
	<link rel="stylesheet" type="text/css" th:href="@{/static/css/personal.css}" media="all">
</head>
<body class="childrenBody">
	<form class="layui-form">
		<div class="layui-form-item">
			<label class="layui-form-label">标题</label>
			<div class="layui-input-block">
				<input class="layui-input newsName" lay-verify="required" placeholder="请输入标题" name="title" id="title" type="text">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">作者</label>
			<div class="layui-input-block">
				<input class="layui-input newsName" lay-verify="required" placeholder="请输入作者" name="auth" id="auth" type="text">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">简介</label>
			<div class="layui-input-block">
				<input class="layui-input newsName" lay-verify="required" placeholder="简介" name="auth" id="introduction" type="text">
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-form-item">
				<label class="layui-form-label">封面图</label>
				<div class="layui-input-block">
					<input id="upload" type="file" name="file" class="layui-upload-file">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">图片预览</label>
				<div class="layui-input-inline">
					<img id="image_upload" src="">
				</div>
			</div>
		</div>
		<div id="div1" style="margin-bottom: 10px">
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button id="submit_btn" class="layui-btn" lay-submit="" lay-filter="addNews">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		</div>
	</form>
	<script type="text/javascript" th:src="@{/static/js/jquery-1.9.1.min.js}"></script>
	<script type="text/javascript" th:src="@{/static/common/layui/layui.js}"></script>
	<script type="text/javascript" th:src="@{/static/js/newsadd.js}"></script>
	<script type="text/javascript" th:src="@{/static/js/wangEditor.min.js}"></script>
	<script type="text/javascript">

        layui.use(['form','upload','layedit','jquery','layer'],function(){
            var $ = layui.$;
            var layer = layui.layer;

			var E = window.wangEditor;
			var editor = new E("#div1");
			editor.customConfig.uploadImgShowBase64 = true;
			editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024
			editor.create();
			console.log(editor.txt.html());



            //建立编辑器
            layui.upload({
                accept: 'images',
                acceptMime: 'image/*',
                url: '/mapmanagement/map/livingBuilding/file/upload' ,//上传接口
                before:function(inputObj){
                    var size = inputObj.files[0].size;
                    if (size > (1*1024*1024)){
                        layer.msg('图片大小不得超过1M',{icon:2});
                        return;
                    }
                    if (size == 0){
                        layer.msg('图片大小不得为空',{icon:2});
                        return;
                    }
                },
                success: function(res){
                    //上传成功后的回调
                    if (res.code == 500){
                        layer.alert(res.msg,function(){
                            layer.close(layer.index);
                        })
                    }else {
                        $("#image_upload").attr("src",res.data.src);
                        $("#image_upload").css("width","300px");
                        $("#image_upload").css("height","200px");
                    }
                }
            });

            $("#submit_btn").on("click",function () {
                //提交按钮
                var title = $("#title").val();
                var imageFile = $("#image_upload").attr("src");
                var auth = $("#auth").val();
                var introduction = $("#introduction").val();
				var wang = editor.txt.html();
                $.ajax({
                    url:"/mapmanagement/gonggao/save",
                    data:{
                        'title': title,
                        'imageFile':imageFile,
                        'auth':auth,
                        'content':wang,
                        'introduction':introduction,
                    },
                    method:'post',
                    dataType:'json',
                    traditional:true,
                    success: function (data) {
                        console.log(data);
                        if (data.code == 500){
                            layer.alert(data.msg, function () {
                                layer.close(layer.index);
                            });
                        } else {
                            layer.alert(data.msg, function () {
                                layer.close(layer.index);
                                // window.location.reload();
                            });
                        }
                    }
                })
            });
        });





	</script>
</body>
</html>